package com.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.core.pojo.SeatReservation.entity.Reservation;
import com.core.pojo.User.dto.UserBlacklistDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ReservationMapper extends BaseMapper<Reservation> {

    /**
     * 查询所有预约过的用户的恶意占座次数（没有就标0）
     */
    @Select("SELECT  user_id," +
            "SUM(CASE WHEN status = 'EXPIRED' THEN 1 ELSE 0 END) AS expired_count " +
            "FROM reservation " +
            "GROUP BY user_id;")
    List<UserBlacklistDTO> selectUserIdsWithExpiredCount();

    @Select("SELECT user_id AS userId, COUNT(*) AS expired_count " +
            "FROM reservation " +
            "WHERE date = #{yesterday} AND status = 'EXPIRED' " +
            "GROUP BY user_id")
    List<UserBlacklistDTO> selectExpiredCountByUser(@Param("yesterday") LocalDate yesterday);
}
